package service;

import dao.FlowerDao;
import entity.Flower;

import java.util.Collections;
import java.util.List;

public class FlowerServiceImpl implements FlowerService {

    private final FlowerDao flowerDao;

    public FlowerServiceImpl(FlowerDao flowerDao) {
        this.flowerDao = flowerDao;
    }

    @Override
    public List<Flower> getAllFlowers() {
        List<Flower> flowers = flowerDao.getAllFlowers();
        return Collections.unmodifiableList(flowers);
    }


    @Override
    public boolean addFlower(Flower flower) {
        if (flower == null) {
            throw new IllegalArgumentException("花名不能为空");
        }
        try {
            return flowerDao.addFlower(flower);
        } catch (Exception e) {
            // 记录异常日志
            System.err.println("添加花名时出错: " + e.getMessage());
            return false;
        }
    }
}
